Debugging Methods and Using Case Structure*136*

*261*There is no separate facility you would traditionally call a “debugger” in Prograph. The entire development environment is integrated and designed for the way programmers work in the real world—code, run, fix, and run again. To see this interactive process in action, do the following:

u
If necessary, click on the OK button (or press Return) to dismiss the “Hello World! My name is Johnny” dialog.

u
Execute the conception method as above.

u
This time, do not type a name at the prompt for a name. Simply press Return.

*101*When you hear two system beeps*1033*, this is Prograph’s signal to let you know your program has run into a problem. Following the signal, the greetings method case window opens. The window background is lightly patterned, and the "join" operation is flashing. *379**408*

This is called a Prograph*359* execution window. The light gray pattern of the background distinguishes it from other Prograph windows. The flashing you see identifies the operation that has run into a problem.

u
Select *505**637*Last Error… *439*from the Info menu, or press Command-L, to find out more about the problem.

The explanatory dialog tells you that the second terminal has received an unacceptable value. While the execution window does not allow you to directly edit the displayed method, it lets you step through the execution of your method and inspect the values and objects that flow through its datalinks.

u
Press Return to dismiss the Last Error… dialog.

How to Examine Data Values During Execution*1087*

There are three ways to inspect*959* values. You can click, double-click, or click-select on any root or terminal in the execution window to inspect and edit its contents in various ways, as follows:

1. Single-Clicking to Inspect a Value

u Single-click the middle terminal of the "join" operation, holding the mouse button down:

The current value of the terminal, NULL, is displayed.

2. Click-Selecting to Open a Value Window*1069*

u Single-click the middle terminal, hold down the mouse, and move the cursor to the NULL value area as shown below:

u Release the mouse, and the Value window for that terminal is displayed:

___________________________________________________________
NOTE: Editing root*957* or terminal*1068* contents can be very useful if you want your program execution to continue without first having to determine the design error leading to the current problem. In this example, you could simply type a name into the text-edit pane of the value window and click OK or press Return to dismiss the window. Press Return at the execution window—Prograph determines that it has the correct input. The execution window disappears, and the greeting dialog is displayed. At some point you need to correct your design error, but for now your method executes.

If you want to try this Prograph feature once more, recreate the current error by not giving the new Person a name.
-----------------------------------------------------------

u
Press Return to dismiss the Value window.

3. Double-Clicking to Open a Value Window

u Double-click the middle terminal of the "join" operation.

The Value window will open for that terminal operation, as before.

u Close the Value window by clicking Cancel.

Editing a Method that is Executing

u
Double-click anywhere on the patterned background of the greetings case window. 

An editable greetings case window *142*(with a clear background) opens. Since a nameless Person situation could arise, greetings can be designed to respond to this by adding a matching test *565*to the name get operation. The test is: “When it is true that the name attribute of a Person is NULL, go to the next case.” This new, second case presents a simple dialog informing the user that no name has been provided.

u
Double-click the right-side root of the name get operation.

u
Command-drag anywhere on the newly added operation and move it to the right so it does not obscure the "join" operation.

Prograph assumes you want to test a value coming out of the root and supplies a default test control annotation (a box containing an X)*1190* attached to the right side of the NULL match operation. Prograph interprets this default test as: “Go to next case if the matched value is not NULL.” That is, if a name is given the newborn person, the test fails. 

You want the test to be just the opposite: “Go to next case if the matched value is NULL.” The control annotation that represents this opposite “when-it-is-true-that…” success condition is a box containing a √ (check mark) to the right of the tested value. The change to this alternative control annotation is made with a single menu choice.

u
In the*579* Controls menu*202*, select the graphical menu item that represents a toggle between the “doesn’t/X” and “does/√” control annotations.

The X annotation flips to a √ *1* annotation. The result is a *1073* matching test that forces execution to continue with the next case when a nameless Person is encountered.

===========================================================
*1099*TIP: Prograph control annotations *196*are an essential part of effective use of method case structure. This example introduces a simple form of control annotation. Specific details on how to interpret and use the wide variety of powerful Prograph control annotations can be found in Part 2, “Tutorials” in this manual.
===========================================================

Your next step is to create this second case. To access the cases of a method, you use the case controls  *132*in the title bar of the case window.
___________________________________________________________
NOTE: A cluster of three control-item icons appear just to the left of the zoom box*1191* of each case window:

Clicks, Shift-clicks, Option-clicks, and Command-clicks on these title-bar controls provide a full range of options to access and create method cases. For the Grand Tour, you use the most basic click to access the Case List pane.*128*
-----------------------------------------------------------

u
Click the middle case-control item to open the Case List pane. The Case List pane has a single icon within it; within that icon is the number 1. This icon represents the single case of greetings.

u
Command-click once just to the right of the first case anywhere within the Case List pane of the case window. This creates a second case icon in the Case List pane.*129*

u
Double-click the icon of the second case in the Case List pane to open the case window for the second case.

The default size and position of the second case is the same as that of the first case. Also note that the new case is created with input- and output-bar roots and terminals that match those of the first case. *171*Any comments on the roots and terminals are also copied into the new case. To get a full view of the two-case structure *137*of the greetings method:

u
Move the second case window to reveal the first case window. Notice the *135*case specification, 2:2, indicating that the new window is for the second of two cases in the greetings method.

u
Command-click a new operation in the center of the second case window, type show, and press Return.

u
Double-click the terminal of the show operation and type OOPS! You forgot to name this person!

u
Press Return to accept the constant prompt and truncate its display.

u
Command-click the close box of the second case window to close both case windows of greetings

The execution window of greetings remains on screen. However, "join" is no longer darkly highlighted. Prograph has performed a*947* rollback to the newly entered match operation. 

___________________________________________________________
*1089*NOTE:*684* When multiple datalinks leave an operation or input-bar root, Prograph always performs operations that involve conditional tests before executing any other operations. In the example, Prograph tests for a NULL name string before attempting the "join" operation.
-----------------------------------------------------------

u
Press Return to execute the match operation.

The execution window closes and the OOPS! You forgot… dialog is displayed. You have encountered and resolved a runtime problem with your Person methods.*680*

u
Press Return to dismiss the dialog.

u
Select Save from the File menu. Type Person and press Return to store your class, including its attributes and methods, on disk.

u
Select Quit from the File menu. The first part of your Grand Tour is complete.

t
Congratulations

You have created your first Prograph class and methods. Your methods create new instances of the class and perform an informative interaction with the user.

In the next chapter of the Grand Tour, you get a taste of actually building an application within the Prograph Development System. You experience how easy it is to add windows, menus, and all the typical Macintosh interface items to your application. Continue now to chapter 3, “The Grand Tour: Application Builder.”